package com.mdd.admin.controller.competition;

import com.mdd.admin.aop.Log;
import com.mdd.admin.service.ICompetitionSiteService;
import com.mdd.admin.validate.commons.IdValidate;
import com.mdd.admin.validate.commons.PageValidate;
import com.mdd.admin.validate.competition.CompetitionSiteCreateValidate;
import com.mdd.admin.validate.competition.CompetitionSiteSearchValidate;
import com.mdd.admin.validate.competition.CompetitionSiteUpdateValidate;
import com.mdd.admin.vo.competition.CompetitionSiteListVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.entity.competition.CompetitionSite;
import com.mdd.common.validator.annotation.IDMust;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/adminapi/competition.site")
@Api(tags = "赛事列管理")
public class CompetitinoSiteContnroller {
    @Resource
    ICompetitionSiteService competitionSiteService;

    @GetMapping("/lists")
    @ApiOperation(value = "赛事列列表")
    public AjaxResult<PageResult<CompetitionSiteListVo>> list(@Validated PageValidate pageValidate,
                                                              @Validated CompetitionSiteSearchValidate searchValidate) {
        PageResult<CompetitionSiteListVo> list = competitionSiteService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }


    @Log(title = "赛事列新增")
    @PostMapping("/add")
    @ApiOperation(value = "赛事列新增")
    public AjaxResult<Object> add(@Validated @RequestBody CompetitionSiteCreateValidate createValidate) {
        competitionSiteService.add(createValidate);
        return AjaxResult.success();
    }

    @Log(title = "赛事列编辑")
    @PostMapping("/edit")
    @ApiOperation(value = "赛事列编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody CompetitionSiteUpdateValidate updateValidate) {
        competitionSiteService.edit(updateValidate);
        return AjaxResult.success();
    }

    @Log(title = "赛事列删除")
    @PostMapping("/del")
    @ApiOperation(value = "赛事列删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        competitionSiteService.del(idValidate.getId());
        return AjaxResult.success();
    }

    @GetMapping("/detail")
    @ApiOperation(value="赛事列详情")
    public AjaxResult<CompetitionSite> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        CompetitionSite detail = competitionSiteService.detail(id);
        return AjaxResult.success(detail);
    }
}
